package org.example.mybooksystem.config;

import org.example.mybooksystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2025-03-07
 * Time: 15:37
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    private static List<String> excludePath= Arrays.asList(
            "/user/login",
            "/**/*.css",
            "/**/*.js",
            "/**/*.html",
            "/**/*.png");

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")// /**表示给所有方案添加拦截器
                .excludePathPatterns(excludePath);// 表示拦截器不进行拦截的接口(白名单)
    }
}
